﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using ZLDC.Common.Estate;

namespace ZLDC.DAL.Estate
{
                public class HousingfavoriteDAL
    {
                                                                                                public static void p_housingfavorite_save(int ID, int UserId, string User, int housingId, int dltFlag, out string outmsg, out int newid, _Database db)
        {
            List<SqlParameter> parms = new List<SqlParameter>();

            parms.Add(new SqlParameter("@ID", ID));
            parms.Add(new SqlParameter("@UserId", UserId));
            parms.Add(new SqlParameter("@User", User));
            parms.Add(new SqlParameter("@housingId", housingId));
            parms.Add(new SqlParameter("@dltFlag", dltFlag));

            SqlParameter pOutmsg = new SqlParameter("@outmsg", SqlDbType.VarChar, 256);
            pOutmsg.Direction = ParameterDirection.Output;
            parms.Add(pOutmsg);

            SqlParameter pNewid = new SqlParameter("@newid", SqlDbType.Int, 4);
            pNewid.Direction = ParameterDirection.Output;
            parms.Add(pNewid);

            db.execute_procedure("p_housingfavorite_save", parms);

            outmsg = (pOutmsg.Value == System.DBNull.Value) ? "" : Convert.ToString(pOutmsg.Value);
            newid = (pNewid.Value == System.DBNull.Value) ? 0 : Convert.ToInt32(pNewid.Value);

        }

                                public static int HousingFavoriteDel(int userid, int housingid, _Database db)
        {
            int rows = 0;

            try
            {
                string sql = "delete t_housingfavorite where UserId = " + userid + " and housingId = " + housingid;
                rows = db.ExecuteSql(sql);
            }
            catch { }
            finally { db.close(); }

            return rows;
        }
    }
}
